package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/*
3. 获取成员方法们：
   - Method[] getMethods()
   - Method getMethod(String name, 类<?>... parameterTypes)
   - Method[] getDeclaredMethods()
   - Method getDeclaredMethod(String name, 类<?>... parameterTypes)
4. 获取全类名
   - String getName()
 */
public class ReflectMethosd {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class personClass = Person.class;

        //Method getMethod(String name, 类<?>... parameterTypes)
        Person person=new Person();
        Method eat_method = personClass.getMethod("eat");
        eat_method.invoke(person);
        //加入方法参数
        Method eat_method1 = personClass.getMethod("eat",String.class);
        eat_method1.invoke(person,"rice");

        //Method[] getMethods()
        Method[] methods = personClass.getMethods();
        for (Method m:methods) {
            //获取方法名
            System.out.print(m.getName()+"===>");
            System.out.println("[" + m + "]");
        }

        //获取类名
        String className = personClass.getName();
        System.out.println("className = [" + className + "]");

    }
}
